package io.renren.modules.medical.controller;

import io.renren.common.result.Result;
import io.renren.common.utils.PageUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.UpdateGroup;
import io.renren.modules.medical.entity.HealthGuidanceEntity;
import io.renren.modules.medical.service.HealthGuidanceService;
import io.renren.modules.medical.vo.medicalVo.StatusVo;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.Map;




/**
 * 
 *健康指导
 * @author luosheng
 * @email luoshengshuai@foxmail.com
 * @date 2023-03-31 09:15:43
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/medical/health/guidance")
public class HealthGuidanceController {

    private final HealthGuidanceService healthGuidanceService;

    /**
     * 列表
     */
    @RequiresPermissions("proposal:healthguidance:list")
    @GetMapping("/list")
    public Result<PageUtils> list(@RequestParam Map<String, Object> params){
        PageUtils page = healthGuidanceService.queryPage(params);
        return Result.success(page);
    }

    /**
     * 信息
     */
    @RequiresPermissions("proposal:healthguidance:info")
    @GetMapping("/info/{id}")
    public Result<HealthGuidanceEntity> info(@PathVariable("id") Long id){
		HealthGuidanceEntity healthGuidance = healthGuidanceService.getById(id);
        return Result.success(healthGuidance);
    }

    /**
     * 保存
     */
    @RequiresPermissions("proposal:healthguidance:save")
    @PostMapping("/save")
    public Result<String> save(@Validated(AddGroup.class) @RequestBody HealthGuidanceEntity healthGuidance){
		healthGuidanceService.saveHealthGuidance(healthGuidance);
        return Result.success(null);
    }

    /**
     * 修改
     */
    @RequiresPermissions("proposal:healthguidance:update")
    @PostMapping("/update")
    public Result<String> update(@Validated(UpdateGroup.class) @RequestBody HealthGuidanceEntity healthGuidance){
		healthGuidanceService.updateById(healthGuidance);
        return Result.success(null);
    }

    /**
     * 删除
     */
    @RequiresPermissions("proposal:healthguidance:delete")
    @PostMapping("/delete")
    public Result<String> delete(@RequestBody @NotNull Long[] ids){
		healthGuidanceService.removeByIds(Arrays.asList(ids));
        return Result.success(null);
    }

    /**
     * 修改状态
     */
    @RequiresPermissions("proposal:healthguidance:update")
    @PostMapping("/updateStatus")
    public Result<String> updateStatus(@RequestBody StatusVo statusVo){
        healthGuidanceService.updateStatus(statusVo);
        return Result.success(null);
    }

    /**
     * 审核
     */
    @RequiresPermissions("proposal:healthguidance:audit")
    @PostMapping("/audit")
    public Result<String> audit(@RequestBody StatusVo statusVo){
        healthGuidanceService.updateStatus(statusVo);
        return Result.success(null);
    }

}
